<?php
 global $objTemplate, $arrConfig,$sCanEdit,$lang;
  $sCanEdit = 1;  
      $objXajax->registerFunction("loadGrid");
  # start region process data 
initPage();
    function  initPage(){ 
  global $bodygrid,$objTemplate,$objDbSelect,$maxPowerType,$formTitle ; 
  
     $formTitle = 'quan ly Loai Quyen'; 
     $maxPowerType =  getMaxPowerType();
     $arrdata =  getPowerTypeInfo();        
       $bodygrid ='';
        for($i=0;$i<count($arrdata);$i++){
           $name_vi = $arrdata[$i]['name_vi'];
           $name_en = $arrdata[$i]['name_en'];
           $power_type = $arrdata[$i]['power_type'];
           $id = $arrdata[$i]['id'];
           $bodygrid .= "<tr>
            <td>$name_vi</td>
            <td>$name_en</td>
            <td>$power_type</td>
            <td>$id</td>
            </tr>";
       }
  }
  
  function getPowerTypeInfo(){
      
      $arrField = array('id','name_vi','name_en','power_type');
      $arrCondition = array('active'=>'1');
      $result = SelectDB('tbl_power_type',$arrField,$arrCondition);
      return $result;
  }
  
  function getMaxPowerType(){
      global $objDbSelect;
      $result =1;
      $sql = "select max(power_type_id) as num from tbl_power_type";
      $arr = $objDbSelect->GetArray($sql);
      if(count($arr)>0){
        $result =  $arr[0]['num']+1;
      }
      return $result; 
  }
    
  function loadGrid(){      

    global $lang,$objDbSelect;
    $lang ='vi';
    $arrGrid = GetGrid();
    $objResponse = new xajaxResponse();
    $oTbs = new clsTinyButStrong();
    $oTbs->LoadTemplate('templates/'.$lang.'/main_powers_type_grid.html');
    $oTbs->MergeBlock('blk_data', $arrGrid);
    $oTbs->Show(TBS_NOTHING);
    $objResponse->addAssign('divGrid', 'innerHTML', $oTbs->Source); 
    $objResponse->addScriptCall('initTable();');                              
    return $objResponse->getXML();    
  }
  
  function  GetGrid(){
    global $objDbSelect;
    $sqlSelect = 'select *,if(active=1,"icon-active","icon-deactivated") as image,if(active=1,"Ngừng kích hoạt","Kích hoạt") as title from tbl_power_type order by name_vi';
   // echo $sqlSelect; die();
    return $objDbSelect->GetArray($sqlSelect);
}
  
  # end region process data
?>
